package com.rrd.dw.azkaban;

import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;

import com.rrd.dw.azkaban.flow.Flow;
import com.rrd.dw.azkaban.flow.Node;
import com.rrd.dw.azkaban.flow.Props;

public class ParesFlow {

    public static void main(String[] args) {
        ParesFlow pf = new ParesFlow();
        pf.deal_flow_again();

    }

    public void deal_flow_again() {
        Logger logger = Logger.getLogger("ParesFlow");
        boolean flag = false;
        Props p = new Props();
        DirectoryFlowLoader fl = new DirectoryFlowLoader(p, logger);
//        fl.loadProjectFlow(new File("E:\\数据研究院\\数据仓库\\git_dw\\azkaban\\dw"));
        fl.loadProjectFlow(new File("../../"));
        Map<String, Flow> flowMap = fl.getFlowMap();
        Map<String, String> jobMap = new HashMap<>();
        for (Flow f : flowMap.values()) {
            Collection<Node> nodes = f.getNodes();
            System.out.println("工作流名称:" + f.getId() + ",总任务数:" + nodes.size());
            for (Node n : nodes) {
                if (!"dw-start".equals(n.getId())
                    && jobMap.containsKey(n.getId())) {
                    flag = true;
                    System.out.println("【ERROR】Job:" + n.getId() + " 出现在多个工作流中:"
                        + jobMap.get(n.getId()) + "," + f.getId());
                }
                jobMap.put(n.getId(), f.getId());
//                System.out.println(n.getId());
            }
        }
        if (flag) {
            System.exit(-1);
        }

    }
}
